import CORS from 'koa2-cors';
import Koa from 'koa';

export const KoaCORS = (options: { [key: string]: any } = {}) => {
    return CORS(
        Object.assign(
            {
                origin: function (ctx: Koa.Context) {
                    const allowList = ['*'];
                    return "*";
                },
                exposeHeaders: ['Authorization'],
                maxAge: 5,
                credentials: true,
                allowMethods: ['OPTIONS', 'GET', 'PUT', 'POST', 'DELETE', 'PATCH'],
                allowHeaders: ['x-requested-with', 'Content-Type', 'Authorization', 'Accept'],
            }, options)
    );
}